//
//  UMSocialMgr.m
//  DoulinClient
//
//  Created by YLKJ on 2019/2/26.
//

#import "UMSocialMgr.h"

@implementation UMSocialMgr
+ (void)shareMsgObj:(UMSocialMessageObject *)msgObj vc:(UIViewController *)vc success:(void(^)(id data))success failure:(void(^)(void))failure {
    //设置分享面板
    [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewBackgroundColor = [UIColor whiteColor];
    [UMSocialShareUIConfig shareInstance].shareContainerConfig.isShareContainerHaveGradient = NO;
    [UMSocialShareUIConfig shareInstance].shareContainerConfig.shareContainerBackgroundColor = [UIColor whiteColor];
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewBackgroundColor = [UIColor whiteColor];
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageBGColor = [UIColor whiteColor];
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_None;
    [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = NO;
    [UMSocialShareUIConfig shareInstance].shareCancelControlConfig.isShow = NO;
    //设置平台
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone)]];
    //弹出分享面板
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        //调用分享接口
        [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:msgObj currentViewController:vc completion:^(id data, NSError *error) {
            if (error) {
                showAlert(@"分享失败!");
                NSLog(@"<-- %s, %d --> %@", __FUNCTION__, __LINE__, error.localizedDescription);
                if (failure) {
                    failure();
                }
            }else{
                //showAlert(@"分享成功!");
                if (success) {
                    success(data);
                }
                if ([data isKindOfClass:UMSocialShareResponse.class]) {
                    UMSocialShareResponse *resp = (UMSocialShareResponse *)data;
                    NSLog(@"<-- %s, %d --> %@", __FUNCTION__, __LINE__, resp);
                }
            }
        }];
    }];
}
@end
